package org.example.exception;

import lombok.Getter;
import org.example.enums.CommEnum;

/**
 * @author
 * @desc
 **/
@Getter
public class CommRuntimeException extends RuntimeException {

    private static final String MESSAGE_FORMAT = "ErrorCode:%d ; ErrorMessage:%s ; ExceptionMessage:%s ; ";

    private Integer errorCode;
    private String errorMessage;

    public CommRuntimeException() {
        super();
    }

    public CommRuntimeException(String message, Throwable cause) {
        super(message, cause);
    }

    public CommRuntimeException(String message) {
        super(message);
    }

    public CommRuntimeException(Throwable cause) {
        super(cause);
    }

    /**
     * 构造方法
     *
     * @param errCode
     * @param errMsg
     */
    public CommRuntimeException(Integer errCode, String errMsg) {
        super(String.format(MESSAGE_FORMAT, errCode, errMsg, null));
        this.errorCode = errCode;
        this.errorMessage = errMsg;
    }


    /**
     * 基于commEnum的构造方法
     *
     * @param commEnum
     */
    public CommRuntimeException(CommEnum<Integer> commEnum) {
        super(String.format(MESSAGE_FORMAT, commEnum.getCode(), commEnum.getContent(), "null"));
        this.errorCode = commEnum.getCode();
        this.errorMessage = commEnum.getContent();
    }





}
